﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Perform
{
    public partial class frmFlowerInsert : Form
    {
        public frmFlowerInsert()
        {
            InitializeComponent();
        }

        private void frmFlowerInsert_Load(object sender, EventArgs e)
        {
            string sql = "select iid from inventory";
            SqlDataReader sdr = Dal.DataHelper.ExecuteReader(sql);
            while (sdr.Read())
            {
                cobiid.Items.Add(sdr["iid"].ToString());
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sql = string.Format("select * from inventory where iid = {0}",cobiid.Text.Trim());
            SqlDataReader sdr = Dal.DataHelper.ExecuteReader(sql);
            while (sdr.Read())
            {
                txtName.Text = sdr["iname"].ToString();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string flanguage = txtflanguage.Text.Trim();
            string fname = txtfname.Text.Trim();
            string fprice = txtfprice.Text.Trim();
            string salecost = txtfsalecost.Text.Trim();
            string iid = cobiid.Text.Trim();
            string sql = string.Format("select count(1) from flower where fname = '{0}'", fname);

            if (flanguage == "" || fname ==""||fprice == "" || salecost == "" || iid == "")
            {
                MessageBox.Show("请输入完整的信息！");
            }
            else if (Dal.DataHelper.sqlExecuteScalar(sql) == 0)
            {
                sql = string.Format("insert into flower values('{0}','{1}','{2}','{3}','{4}')", fname, flanguage, fprice, salecost, iid);
                if (Dal.DataHelper.sqlExecuteNonQuery(sql) > 0)
                {
                    MessageBox.Show("添加成功！");
                }
            }
            else
            {
                MessageBox.Show("该鲜花已存在！");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            txtflanguage.Text = "";
            txtfname.Text = "";
            txtfprice.Text = "";
            txtfsalecost.Text = "";
            cobiid.Text = "----------请选择仓库编号----------";
            txtName.Text = "";
        }
    }
}
